package com.china.tool;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.china.pojo.BusinessHandling;
import com.china.pojo.Combo;
import com.china.service.BusinessHandlingService;
import com.china.service.ComboService;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

@Component
public class MyTool {

    @Autowired
    private ComboService comboService;


    @Tool(description = "根据条件回答")
    public List<Combo> queryCourse(@ToolParam(required = false,description = "套餐选择的条件") CourseQuery query ){
        if (query == null){
            return comboService.list();
        }
        //查询表 select * from course where packageName = ? and type = ?
        QueryWrapper<Combo> qw = new QueryWrapper<>();
        qw.le(query.getMonthlyRent() != null,"monthlyRent",query.getMonthlyRent());
        qw.eq("contractPeriod",query.getPackageName());
        return comboService.list(qw);
    }

    //todo
    public List<Combo> queryCourse2(@ToolParam(required = false,description = "用户询问的条件") CourseQuery query){
        QueryWrapper<Combo> qw = new QueryWrapper<>();
        qw.like(StrUtil.isNotBlank(query.getContractPeriod()),"contractPeriod",query.getContractPeriod());

        return comboService.list(qw);
    }

    @Tool(description = "查询所有套餐")
    public List<Combo> queryAllSchools(){
        return comboService.list();
    }

    @Autowired
    private BusinessHandlingService service;
    //todo
    @Tool(description = "办理套餐,并存到business_handling表中,其中客户名字,套餐的名称,月租,流量,通话市场,附加服务,合约期是必填的,给客户提供办理方式（如“回复‘办理’或前往APP操作”）")
    public String generateCourseReservation (@ToolParam (description = "客户名字")   String  customerName ,
                                             @ToolParam(description = "办理的套餐名称")   String  packageName ,
                                             @ToolParam(description = "套餐的月租")      String  monthlyRent,
                                             @ToolParam(description = "套餐的流量")      String  traffic,
                                             @ToolParam(description = "套餐的通话时长")   String  callDuration,
                                             @ToolParam(required = false,description = "套餐的附加服务")  String additionalServices,
                                             @ToolParam(required = false,description = "套餐的合约期")    String contractPeriod){
        BusinessHandling build = BusinessHandling.builder()
                .customerName(customerName)
                .packageName(packageName)
                .monthlyRent(monthlyRent)
                .traffic(traffic)
                .callDuration(callDuration)
                .additionalServices(additionalServices)
                .contractPeriod(contractPeriod)
                .handlingTime(LocalDateTime.now())
                .build();
        service.save(build);
        return build.getId().toString();
    }
}
